import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:hook_rent/pages/home/info/data.dart';
import 'package:hook_rent/widgets/image_widget.dart';
import 'package:hook_rent/widgets/text_widgets.dart';

class ItemWidget extends StatelessWidget {
  final InfoItem data;
  const ItemWidget(this.data, {super.key});

  @override
  // 构建方法，返回一个包含图片、标题、来源和时间的容器
  Widget build(BuildContext context) {
    return Container(
      decoration: const BoxDecoration(
        color: Colors.white,
      ),
      height: 100.h,
      padding: EdgeInsets.only(
        left: 10.w,
        right: 10.w,
        bottom: 10.w,
      ),
      child: Row(
        children: [
          ImageWidget(
            data.imageUrl,
            width: 120.w,
            height: 90.w,
          ),
          SizedBox(width: 10.w), // 使用SizedBox代替Padding，减少冗余代码
          Expanded(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              crossAxisAlignment: CrossAxisAlignment.start, // 确保文本对齐
              children: [
                Text(
                  data.title,
                  style:
                      TextStyle(fontSize: 14.sp, fontWeight: FontWeight.w500),
                  maxLines: 2,
                  overflow: TextOverflow.ellipsis, // 添加文本溢出处理
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    text14Normal(text: data.source ?? '未知来源'), // 添加默认值处理
                    text14Normal(text: data.time ?? '未知时间'), // 添加默认值处理
                  ],
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
